﻿using Zws.Common.ScanTool;
using Microsoft.EntityFrameworkCore;

namespace Zws.Dapper
{
    public abstract class ZwsDbContext : DbContext
    {
        public ZwsDbContext(DbContextOptions options) : base(options)
        {
        }
        //     Override this method to configure the database (and other options) to be used
        //     for this context. This method is called for each instance of the context that
        //     is created. The base implementation does nothing.
        //     In situations where an instance of Microsoft.EntityFrameworkCore.DbContextOptions
        //     may or may not have been passed to the constructor, you can use Microsoft.EntityFrameworkCore.DbContextOptionsBuilder.IsConfigured
        //     to determine if the options have already been set, and skip some or all of the
        //     logic in Microsoft.EntityFrameworkCore.DbContext.OnConfiguring(Microsoft.EntityFrameworkCore.DbContextOptionsBuilder).
        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            Console.WriteLine("AppContext is Creating..........biubiubiu");
            base.OnConfiguring(optionsBuilder);
        }
        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            ScanHelper.ScanSpecialPublicClassByAssemblys(type =>
            type.IsAssignableTo(typeof(BaseEntity))
            && !type.Name.Equals(typeof(BaseEntity).Name))
             .ForEach(x =>
             {
                 modelBuilder.Entity(x);
             });
        }
    }
}
